package mdFile

import (
	"editor/dao"
	"github.com/gin-gonic/gin"
)

func GetListItemWithDir(c *gin.Context) (newList []*dao.MDListItem, err error) {
	return dao.GetListItem4Index(c, false)
}

func GetListItemWithDir4Admin(c *gin.Context) (newList []*dao.MDListItem, err error) {
	return dao.GetListItem4Index(c, true)
}

func GetDefaultId(newList []*dao.MDListItem) int64 {
	if len(newList) == 0 {
		return 0
	}

	for i := 0; i < len(newList); i++ {
		if newList[i].IsCategory == 1 {
			if len(newList[i].ChildList) == 0 {
				continue
			}
			return newList[i].ChildList[0].Id
		} else {
			return newList[i].Id
		}
	}
	return 0
}
